package site.zhangzhuo.v1;

import java.io.Serial;
import java.io.Serializable;
import java.util.HashMap;

//法
public class Fa implements Serializable {
    @Serial
    private static final long serialVersionUID= 3L;
    private final String ming;//法名
    private final HashMap<String,Fa> shu=new HashMap<>();//所属法
    private final HashMap<String,Fa> sheng=new HashMap<>();//所生法
    private final HashMap<String,Fa> dui=new HashMap<>();//所对法
    private final HashMap<String,Fa> jin=new HashMap<>();//所近法

    public Fa(String tming){
        this.ming=tming;
    }
    public Fa(char danzi){
        ming=String.valueOf(danzi);
    }
    public String getMing(){
        return ming;
    }
    //添加关系法
    public void addRelationFa(Relation rela,Fa tfa){
        switch (rela){
            case DUI:
                this.addDui(tfa);
                tfa.addDui(this);
                break;
            case SHU:
                this.addShu(tfa);
                break;
            case SHENG:
                this.addSheng(tfa);
                break;
            case JIN:
                this.addJin(tfa);
                break;
        }
    }
    //添加所属法
    public void addShu(Fa tfa) {
        this.shu.putIfAbsent(tfa.getMing(),tfa);
    }
    //添加所生法
    public void addSheng(Fa tfa) {
        this.sheng.putIfAbsent(tfa.getMing(),tfa);
    }
    //添加所对法
    public void addDui(Fa tfa) {
        this.dui.putIfAbsent(tfa.getMing(),tfa);
    }
    //添加所近法
    public void addJin(Fa tfa) {
        this.jin.putIfAbsent(tfa.getMing(),tfa);
    }
    //所对是否为null
    public boolean isEmptyDui(){
        if (dui.isEmpty())return true;
        else return false;
    }
    //某种关系是否为空
    public boolean isEmpty(Relation rela){
        switch (rela){
            case DUI:
                if (dui.isEmpty())return true;
                break;
            case SHU:
                if (shu.isEmpty())return true;
                break;
            case SHENG:
                if (sheng.isEmpty())return true;
                break;
            case JIN:
                if (jin.isEmpty())return true;
                break;
        }
        return false;
    }
    @Override
    public String toString(){
        return this.ming;
    }
}
